package study.week05.bytebuddy.aop;

import net.bytebuddy.asm.Advice;

import java.lang.reflect.Method;
import java.util.Arrays;

class AspectAdvisor {


    @Advice.OnMethodEnter
    public static void onMethodEnter( @Advice.This Object target, @Advice.Origin Method method, @Advice.AllArguments Object[] arguments) {
        //只对加了@Aspect注解的对象执行
        if (method.getAnnotation(Aspect.class) != null) {
            System.out.println("AOP:进入方法前 对象:" + target + " 方法:" + method.getName() + " 参数: " + Arrays.toString(arguments));
        }
    }

    @Advice.OnMethodExit
    public static void onMethodExit(@Advice.This Object target, @Advice.Origin Method method, @Advice.AllArguments Object[] arguments, @Advice.Return Object ret) {
        //只对加了@Aspect注解的对象执行
        if (method.getAnnotation(Aspect.class) != null) {
            System.out.println("AOP:方法运行后 对象:" + target + " 方法:" + method.getName() + " 参数: " + Arrays.toString(arguments) + " 返回值: " + ret);
        }
    }

}